// 英语句子和单词数据
const sentenceData = [
    {
        "id": 1,
        "sentence": "It's time for us to have lunch.",
        "words": ["It's", "time", "for", "us", "to", "have", "lunch"]
    },
    {
        "id": 2,
        "sentence": "She had an egg, a piece of bread and some milk for breakfast.",
        "words": ["She", "had", "an", "egg", "a", "piece", "of", "bread", "and", "some", "milk", "for", "breakfast"]
    },
    {
        "id": 3,
        "sentence": "Which fruit do you like, apples or oranges?",
        "words": ["Which", "fruit", "do", "you", "like", "apples", "or", "oranges"]
    },
    {
        "id": 4,
        "sentence": "The fish soup tasted so good that the guests asked for more.",
        "words": ["The", "fish", "soup", "tasted", "so", "good", "that", "the", "guests", "asked", "for", "more"]
    },
    {
        "id": 5,
        "sentence": "She usually gets up at half past seven in the morning.",
        "words": ["She", "usually", "gets", "up", "at", "half", "past", "seven", "in", "the", "morning"]
    },
    {
        "id": 6,
        "sentence": "My grandpa used to have a walk in the garden after supper.",
        "words": ["My", "grandpa", "used", "to", "have", "a", "walk", "in", "the", "garden", "after", "supper"]
    },
    {
        "id": 7,
        "sentence": "At weekends, some people like to stay at home, but others like to go for a walk or have a picnic.",
        "words": ["At", "weekends", "some", "people", "like", "to", "stay", "at", "home", "but", "others", "like", "to", "go", "for", "a", "walk", "or", "have", "a", "picnic"]
    },
    {
        "id": 8,
        "sentence": "I called you yesterday evening, but there was no answer.",
        "words": ["I", "called", "you", "yesterday", "evening", "but", "there", "was", "no", "answer"]
    },
    {
        "id": 9,
        "sentence": "On Saturday, I will help my mom with the housework.",
        "words": ["On", "Saturday", "I", "will", "help", "my", "mom", "with", "the", "housework"]
    },
    {
        "id": 10,
        "sentence": "The children are listening to the radio while they are cleaning the windows.",
        "words": ["The", "children", "are", "listening", "to", "the", "radio", "while", "they", "are", "cleaning", "the", "windows"]
    },
    {
        "id": 11,
        "sentence": "She was making dinner when the phone rang.",
        "words": ["She", "was", "making", "dinner", "when", "the", "phone", "rang"]
    },
    {
        "id": 12,
        "sentence": "After lunch, Ann cleaned the table and washed dishes.",
        "words": ["After", "lunch", "Ann", "cleaned", "the", "table", "and", "washed", "dishes"]
    },
    {
        "id": 13,
        "sentence": "I'll learn about cooking on the Internet.",
        "words": ["I'll", "learn", "about", "cooking", "on", "the", "Internet"]
    },
    {
        "id": 14,
        "sentence": "Chinese people are very good at table tennis, and it's our favorite sport.",
        "words": ["Chinese", "people", "are", "very", "good", "at", "table", "tennis", "and", "it's", "our", "favorite", "sport"]
    },
    {
        "id": 15,
        "sentence": "He is one of the tallest basketball players in the world.",
        "words": ["He", "is", "one", "of", "the", "tallest", "basketball", "players", "in", "the", "world"]
    },
    {
        "id": 16,
        "sentence": "He's going to the nearby valley to take part in a mountain bike race.",
        "words": ["He's", "going", "to", "the", "nearby", "valley", "to", "take", "part", "in", "a", "mountain", "bike", "race"]
    },
    {
        "id": 17,
        "sentence": "My favourite subject is science because I can do experiments during the class.",
        "words": ["My", "favourite", "subject", "is", "science", "because", "I", "can", "do", "experiments", "during", "the", "class"]
    },
    {
        "id": 18,
        "sentence": "To make your dream come true, you should study hard.",
        "words": ["To", "make", "your", "dream", "come", "true", "you", "should", "study", "hard"]
    },
    {
        "id": 19,
        "sentence": "We learned from each other in and out of class.",
        "words": ["We", "learned", "from", "each", "other", "in", "and", "out", "of", "class"]
    },
    {
        "id": 20,
        "sentence": "This dictionary was very cheap and it only cost me twelve dollars.",
        "words": ["This", "dictionary", "was", "very", "cheap", "and", "it", "only", "cost", "me", "twelve", "dollars"]
    },
    {
        "id": 21,
        "sentence": "There are some books, a pen and a pencil on the desk.",
        "words": ["There", "are", "some", "books", "a", "pen", "and", "a", "pencil", "on", "the", "desk"]
    },
    {
        "id": 22,
        "sentence": "They have four lessons in the morning and two in the afternoon.",
        "words": ["They", "have", "four", "lessons", "in", "the", "morning", "and", "two", "in", "the", "afternoon"]
    },
    {
        "id": 23,
        "sentence": "Our class teacher asked the monitor why Bill didn't come to school.",
        "words": ["Our", "class", "teacher", "asked", "the", "monitor", "why", "Bill", "didn't", "come", "to", "school"]
    },
    {
        "id": 24,
        "sentence": "Miss Green taught us English four years ago.",
        "words": ["Miss", "Green", "taught", "us", "English", "four", "years", "ago"]
    },
    {
        "id": 25,
        "sentence": "Tom never forgets to turn off the lights when he leaves the classroom.",
        "words": ["Tom", "never", "forgets", "to", "turn", "off", "the", "lights", "when", "he", "leaves", "the", "classroom"]
    },
    {
        "id": 26,
        "sentence": "I finished doing my homework and then I had a rest.",
        "words": ["I", "finished", "doing", "my", "homework", "and", "then", "I", "had", "a", "rest"]
    },
    {
        "id": 27,
        "sentence": "Wish you every success in your exams.",
        "words": ["Wish", "you", "every", "success", "in", "your", "exams"]
    },
    {
        "id": 28,
        "sentence": "Jane was sure that she had left her wallet in the classroom.",
        "words": ["Jane", "was", "sure", "that", "she", "had", "left", "her", "wallet", "in", "the", "classroom"]
    },
    {
        "id": 29,
        "sentence": "It's said that our school's paper comes out once a week.",
        "words": ["It's", "said", "that", "our", "school's", "paper", "comes", "out", "once", "a", "week"]
    },
    {
        "id": 30,
        "sentence": "I think our school life is full of laughing.",
        "words": ["I", "think", "our", "school", "life", "is", "full", "of", "laughing"]
    },
    {
        "id": 31,
        "sentence": "We're going to leave our primary school soon and start middle school this September.",
        "words": ["We're", "going", "to", "leave", "our", "primary", "school", "soon", "and", "start", "middle", "school", "this", "September"]
    },
    {
        "id": 32,
        "sentence": "I like football, reading, swimming and singing songs.",
        "words": ["I", "like", "football", "reading", "swimming", "and", "singing", "songs"]
    },
    {
        "id": 33,
        "sentence": "It's very hot in summer, so I like to go swimming.",
        "words": ["It's", "very", "hot", "in", "summer", "so", "I", "like", "to", "go", "swimming"]
    },
    {
        "id": 34,
        "sentence": "Listen! The girls are singing in the music room.",
        "words": ["Listen", "The", "girls", "are", "singing", "in", "the", "music", "room"]
    },
    {
        "id": 35,
        "sentence": "She began to learn the piano at the age of five.",
        "words": ["She", "began", "to", "learn", "the", "piano", "at", "the", "age", "of", "five"]
    },
    {
        "id": 36,
        "sentence": "Here is a story about air and water.",
        "words": ["Here", "is", "a", "story", "about", "air", "and", "water"]
    },
    {
        "id": 37,
        "sentence": "We will have an English party next Sunday.",
        "words": ["We", "will", "have", "an", "English", "party", "next", "Sunday"]
    },
    {
        "id": 38,
        "sentence": "We gave Mum a surprising party on her fortieth birthday.",
        "words": ["We", "gave", "Mum", "a", "surprising", "party", "on", "her", "fortieth", "birthday"]
    },
    {
        "id": 39,
        "sentence": "This morning, Tina and I flew my new kite in the park, but it wasn't windy in the park.",
        "words": ["This", "morning", "Tina", "and", "I", "flew", "my", "new", "kite", "in", "the", "park", "but", "it", "wasn't", "windy", "in", "the", "park"]
    },
    {
        "id": 40,
        "sentence": "It's very kind of you to help me get the ticket for the concert.",
        "words": ["It's", "very", "kind", "of", "you", "to", "help", "me", "get", "the", "ticket", "for", "the", "concert"]
    },
    {
        "id": 41,
        "sentence": "The students couldn't help laughing when they heard the joke.",
        "words": ["The", "students", "couldn't", "help", "laughing", "when", "they", "heard", "the", "joke"]
    },
    {
        "id": 42,
        "sentence": "We were tired so we stayed at home.",
        "words": ["We", "were", "tired", "so", "we", "stayed", "at", "home"]
    },
    {
        "id": 43,
        "sentence": "I was very curious about how he spent his money.",
        "words": ["I", "was", "very", "curious", "about", "how", "he", "spent", "his", "money"]
    },
    {
        "id": 44,
        "sentence": "Tom was in a blue mood, because he lost the race.",
        "words": ["Tom", "was", "in", "a", "blue", "mood", "because", "he", "lost", "the", "race"]
    },
    {
        "id": 45,
        "sentence": "We are going to invite my uncle, aunt and cousins for dinner.",
        "words": ["We", "are", "going", "to", "invite", "my", "uncle", "aunt", "and", "cousins", "for", "dinner"]
    },
    {
        "id": 46,
        "sentence": "Thanks for your invitation to have dinner, but I can't come.",
        "words": ["Thanks", "for", "your", "invitation", "to", "have", "dinner", "but", "I", "can't", "come"]
    },
    {
        "id": 47,
        "sentence": "I'm sorry to hear that.",
        "words": ["I'm", "sorry", "to", "hear", "that"]
    },
    {
        "id": 48,
        "sentence": "On each shelf, the books are lined up in order from smallest to largest.",
        "words": ["On", "each", "shelf", "the", "books", "are", "lined", "up", "in", "order", "from", "smallest", "to", "largest"]
    },
    {
        "id": 49,
        "sentence": "When we arrived at Ted's house, his dog Guinness welcomed us.",
        "words": ["When", "we", "arrived", "at", "Ted's", "house", "his", "dog", "Guinness", "welcomed", "us"]
    },
    {
        "id": 50,
        "sentence": "Jack, a close friend of mine, will come and join us in the game.",
        "words": ["Jack", "a", "close", "friend", "of", "mine", "will", "come", "and", "join", "us", "in", "the", "game"]
    },
    {
        "id": 51,
        "sentence": "The one my dad carried is my older sister, Tina.",
        "words": ["The", "one", "my", "dad", "carried", "is", "my", "older", "sister", "Tina"]
    },
    {
        "id": 52,
        "sentence": "I want to be a doctor like my mom and help more people.",
        "words": ["I", "want", "to", "be", "a", "doctor", "like", "my", "mom", "and", "help", "more", "people"]
    },
    {
        "id": 53,
        "sentence": "It's very nice of you to write to me.",
        "words": ["It's", "very", "nice", "of", "you", "to", "write", "to", "me"]
    },
    {
        "id": 54,
        "sentence": "The new teacher is short, with big eyes.",
        "words": ["The", "new", "teacher", "is", "short", "with", "big", "eyes"]
    },
    {
        "id": 55,
        "sentence": "We all like him because he says little but does much.",
        "words": ["We", "all", "like", "him", "because", "he", "says", "little", "but", "does", "much"]
    },
    {
        "id": 56,
        "sentence": "Joey's hair is a little shorter than Daisy's.",
        "words": ["Joey's", "hair", "is", "a", "little", "shorter", "than", "Daisy's"]
    },
    {
        "id": 57,
        "sentence": "The man was poor but he was honest.",
        "words": ["The", "man", "was", "poor", "but", "he", "was", "honest"]
    },
    {
        "id": 58,
        "sentence": "Many people don't like shopping on the Internet because they can't see the things or try the clothes on.",
        "words": ["Many", "people", "don't", "like", "shopping", "on", "the", "Internet", "because", "they", "can't", "see", "the", "things", "or", "try", "the", "clothes", "on"]
    },
    {
        "id": 59,
        "sentence": "Ben has two pairs of sports shoes but they're old.",
        "words": ["Ben", "has", "two", "pairs", "of", "sports", "shoes", "but", "they're", "old"]
    },
    {
        "id": 60,
        "sentence": "She put on her favorite orange dress.",
        "words": ["She", "put", "on", "her", "favorite", "orange", "dress"]
    },
    {
        "id": 61,
        "sentence": "She has a nice pair of pink gloves.",
        "words": ["She", "has", "a", "nice", "pair", "of", "pink", "gloves"]
    },
    {
        "id": 62,
        "sentence": "It's traditional to eat moon cakes on Mid-Autumn Day in China.",
        "words": ["It's", "traditional", "to", "eat", "moon", "cakes", "on", "Mid-Autumn", "Day", "in", "China"]
    },
    {
        "id": 63,
        "sentence": "My mother will take me to the World Park to learn about the famous places around the world tomorrow.",
        "words": ["My", "mother", "will", "take", "me", "to", "the", "World", "Park", "to", "learn", "about", "the", "famous", "places", "around", "the", "world", "tomorrow"]
    },
    {
        "id": 64,
        "sentence": "Last summer vacation I went to Beijing with my parents.",
        "words": ["Last", "summer", "vacation", "I", "went", "to", "Beijing", "with", "my", "parents"]
    },
    {
        "id": 65,
        "sentence": "We went to the Science Museum last Saturday.",
        "words": ["We", "went", "to", "the", "Science", "Museum", "last", "Saturday"]
    },
    {
        "id": 66,
        "sentence": "When we cross the road, we must follow the traffic rules.",
        "words": ["When", "we", "cross", "the", "road", "we", "must", "follow", "the", "traffic", "rules"]
    },
    {
        "id": 67,
        "sentence": "To keep safe, you can wait on the pavement and look out for cars and bikes.",
        "words": ["To", "keep", "safe", "you", "can", "wait", "on", "the", "pavement", "and", "look", "out", "for", "cars", "and", "bikes"]
    },
    {
        "id": 68,
        "sentence": "You must not play football on the road because there are many cars and bikes.",
        "words": ["You", "must", "not", "play", "football", "on", "the", "road", "because", "there", "are", "many", "cars", "and", "bikes"]
    },
    {
        "id": 69,
        "sentence": "Let's meet at the bus stop at 8 o'clock.",
        "words": ["Let's", "meet", "at", "the", "bus", "stop", "at", "8", "o'clock"]
    },
    {
        "id": 70,
        "sentence": "Maybe you can ride a bike or take a bus instead of driving a car.",
        "words": ["Maybe", "you", "can", "ride", "a", "bike", "or", "take", "a", "bus", "instead", "of", "driving", "a", "car"]
    },
    {
        "id": 71,
        "sentence": "It takes us half an hour to walk to school every day.",
        "words": ["It", "takes", "us", "half", "an", "hour", "to", "walk", "to", "school", "every", "day"]
    },
    {
        "id": 72,
        "sentence": "The train from Tianjinnan arrived an hour ago.",
        "words": ["The", "train", "from", "Tianjinnan", "arrived", "an", "hour", "ago"]
    },
    {
        "id": 73,
        "sentence": "You can go down the street and then turn right at the first corner.",
        "words": ["You", "can", "go", "down", "the", "street", "and", "then", "turn", "right", "at", "the", "first", "corner"]
    },
    {
        "id": 74,
        "sentence": "We mustn't talk or speak loudly in public places like hospitals, libraries or cinemas.",
        "words": ["We", "mustn't", "talk", "or", "speak", "loudly", "in", "public", "places", "like", "hospitals", "libraries", "or", "cinemas"]
    },
    {
        "id": 75,
        "sentence": "Hainan is in the south of China.",
        "words": ["Hainan", "is", "in", "the", "south", "of", "China"]
    },
    {
        "id": 76,
        "sentence": "The bookstore is next to the library.",
        "words": ["The", "bookstore", "is", "next", "to", "the", "library"]
    },
    {
        "id": 77,
        "sentence": "My grandma lives with my uncle in a village not too far away.",
        "words": ["My", "grandma", "lives", "with", "my", "uncle", "in", "a", "village", "not", "too", "far", "away"]
    },
    {
        "id": 78,
        "sentence": "Sitting for a long time at the computer is bad for our health.",
        "words": ["Sitting", "for", "a", "long", "time", "at", "the", "computer", "is", "bad", "for", "our", "health"]
    },
    {
        "id": 79,
        "sentence": "People often need to take some medicine when they catch a cold or a cough.",
        "words": ["People", "often", "need", "to", "take", "some", "medicine", "when", "they", "catch", "a", "cold", "or", "a", "cough"]
    },
    {
        "id": 80,
        "sentence": "It will be cold and windy in Xi'an and it will be sunny and warm in Sanya.",
        "words": ["It", "will", "be", "cold", "and", "windy", "in", "Xi'an", "and", "it", "will", "be", "sunny", "and", "warm", "in", "Sanya"]
    },
    {
        "id": 81,
        "sentence": "The weather is very hot, so the ice turns into water.",
        "words": ["The", "weather", "is", "very", "hot", "so", "the", "ice", "turns", "into", "water"]
    },
    {
        "id": 82,
        "sentence": "The weather forecast says it will be rainy in the late afternoon.",
        "words": ["The", "weather", "forecast", "says", "it", "will", "be", "rainy", "in", "the", "late", "afternoon"]
    },
    {
        "id": 83,
        "sentence": "People plant trees in spring and farmers are busy harvesting in autumn.",
        "words": ["People", "plant", "trees", "in", "spring", "and", "farmers", "are", "busy", "harvesting", "in", "autumn"]
    },
    {
        "id": 84,
        "sentence": "When spring comes, the animals that sleep in winter start waking up.",
        "words": ["When", "spring", "comes", "the", "animals", "that", "sleep", "in", "winter", "start", "waking", "up"]
    },
    {
        "id": 85,
        "sentence": "What a big elephant it is!",
        "words": ["What", "a", "big", "elephant", "it", "is"]
    },
    {
        "id": 86,
        "sentence": "You can see as many as 15,000 butterflies sitting on one branch!",
        "words": ["You", "can", "see", "as", "many", "as", "15000", "butterflies", "sitting", "on", "one", "branch"]
    },
    {
        "id": 87,
        "sentence": "Joy keeps two pets at home and she feeds them after dinner every day.",
        "words": ["Joy", "keeps", "two", "pets", "at", "home", "and", "she", "feeds", "them", "after", "dinner", "every", "day"]
    },
    {
        "id": 88,
        "sentence": "It's your turn to walk the dog.",
        "words": ["It's", "your", "turn", "to", "walk", "the", "dog"]
    },
    {
        "id": 89,
        "sentence": "The girl wants to buy a flower for her mum.",
        "words": ["The", "girl", "wants", "to", "buy", "a", "flower", "for", "her", "mum"]
    },
    {
        "id": 90,
        "sentence": "Now there are only about ten thousand blue whales in the wild.",
        "words": ["Now", "there", "are", "only", "about", "ten", "thousand", "blue", "whales", "in", "the", "wild"]
    },
    {
        "id": 91,
        "sentence": "Most of the kids have never seen the sea.",
        "words": ["Most", "of", "the", "kids", "have", "never", "seen", "the", "sea"]
    },
    {
        "id": 92,
        "sentence": "The moon is round and bright on that day.",
        "words": ["The", "moon", "is", "round", "and", "bright", "on", "that", "day"]
    },
    {
        "id": 93,
        "sentence": "The moon goes around the earth all the time.",
        "words": ["The", "moon", "goes", "around", "the", "earth", "all", "the", "time"]
    },
    {
        "id": 94,
        "sentence": "We shouldn't leave the rubbish anywhere.",
        "words": ["We", "shouldn't", "leave", "the", "rubbish", "anywhere"]
    },
    {
        "id": 95,
        "sentence": "We should not cut down too many trees because trees help keep the air clean.",
        "words": ["We", "should", "not", "cut", "down", "too", "many", "trees", "because", "trees", "help", "keep", "the", "air", "clean"]
    },
    {
        "id": 96,
        "sentence": "We use plastic to make bags and bottles, but too much plastic is bad for the Earth.",
        "words": ["We", "use", "plastic", "to", "make", "bags", "and", "bottles", "but", "too", "much", "plastic", "is", "bad", "for", "the", "Earth"]
    },
    {
        "id": 97,
        "sentence": "We should not drive so much because cars use a lot of energy.",
        "words": ["We", "should", "not", "drive", "so", "much", "because", "cars", "use", "a", "lot", "of", "energy"]
    },
    {
        "id": 98,
        "sentence": "Robots can cheer up sick kids, too.",
        "words": ["Robots", "can", "cheer", "up", "sick", "kids", "too"]
    },
    {
        "id": 99,
        "sentence": "We're going to see a film about space travel!",
        "words": ["We're", "going", "to", "see", "a", "film", "about", "space", "travel"]
    },
    {
        "id": 100,
        "sentence": "They will travel to Mars in a Time Chair.",
        "words": ["They", "will", "travel", "to", "Mars", "in", "a", "Time", "Chair"]
    }
];

// 生成单词选项（6选1）
function generateWordOptions(correctWord, allWords) {
    // 创建一个不包含正确单词的候选池
    const candidates = allWords.filter(word => word !== correctWord);
    
    // 如果候选池不足5个单词，使用全部候选词并补足正确单词
    if (candidates.length < 5) {
        console.warn('警告: 单词候选池不足，无法生成5个不同的干扰项');
        return [correctWord, ...candidates].sort(() => Math.random() - 0.5);
    }
    
    // 使用Fisher-Yates洗牌算法打乱候选池
    for (let i = candidates.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [candidates[i], candidates[j]] = [candidates[j], candidates[i]];
    }
    
    // 选择前5个作为干扰项，并添加正确单词
    const options = [correctWord, ...candidates.slice(0, 5)];
    
    // 再次洗牌以确保正确单词的位置随机
    for (let i = options.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [options[i], options[j]] = [options[j], options[i]];
    }
    
    return options;
}

// 生成句子选项（6选1）
function generateSentenceOptions(correctSentence, allSentences) {
    const options = new Set();
    options.add(correctSentence);
    
    // 从所有句子中随机选择5个干扰项
    while (options.size < 6) {
        const randomIndex = Math.floor(Math.random() * allSentences.length);
        options.add(allSentences[randomIndex]);
    }
    
    // 打乱选项顺序
    return Array.from(options).sort(() => Math.random() - 0.5);
}

// 收集所有单词和句子用于生成选项
const allWords = [...new Set(sentenceData.flatMap(item => item.words))];
const allSentences = sentenceData.map(item => item.sentence);